# frozen_string_literal: true

module GqlTypes
  class BaseObject < GraphQL::Schema::Object
    field_class GqlTypes::BaseField

    # rubocop:disable Metrics/ParameterLists
    def self.preloaded_field(
      field_name,
      type,
      dependency_field_names: nil,
      resolve_func: nil,
      block_db: true,
      **options,
      &block
    )
      field(
        field_name,
        type,
        options.merge(
          function: AssociationPreloader::Preloader.new(
            dependency_field_names,
            resolve_func: resolve_func,
            type: type,
            block_db: block_db
          )
        ),
        &block
      )
    end
    # rubocop:enable Metrics/ParameterLists
  end
end
